home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / raid / devRaidHardInit.c < prev    next >
C/C++ Source or Header  |  1990-11-09  |  7KB  |  263 lines

  1. /* 
  2.  * devRaidHardInit.c --
  3.  *
  4.  *    This file implements routines for regenerating the parity.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #include "sync.h"
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "sprite.h"
  21. #include "fs.h"
  22. #include "dev.h"
  23. #include "devBlockDevice.h"
  24. #include "devRaid.h"
  25. #include "semaphore.h"
  26. #include "stdlib.h"
  27. #include "devRaidUtil.h"
  28. #include "schedule.h"
  29. #include "devRaidProto.h"
  30.  
  31.  
  32. /*
  33.  *----------------------------------------------------------------------
  34.  *
  35.  * Raid_InitiateHardInit --
  36.  *    
  37.  *    Reconstructs the parity beginning at startStripe for numStripe.
  38.  *    If numStripe is negative, all stripes will be reconstucted.
  39.  *    (ctrlData is used by the debug device when debugging in user mode.)
  40.  *
  41.  * Results:
  42.  *    None.
  43.  *
  44.  * Side effects:
  45.  *    Parity is updated.
  46.  *
  47.  *----------------------------------------------------------------------
  48.  */
  49.  
  50. static void InitiateStripeHardInit();
  51. static void hardInitReadDoneProc();
  52. static void hardInitWriteDoneProc();
  53.  
  54. void
  55. Raid_InitiateHardInit(raidPtr, startStripe, numStripe, doneProc,clientData,ctrlData)
  56.     Raid    *raidPtr;
  57.     int         startStripe;
  58.     int         numStripe;
  59.     void       (*doneProc)();
  60.     ClientData   clientData;
  61.     int         ctrlData;
  62. {
  63.     RaidReconstructionControl    *reconstructionControlPtr;
  64.     reconstructionControlPtr =
  65.         Raid_MakeReconstructionControl(raidPtr, (int) NIL, (int) NIL,
  66.             (RaidDisk *) NIL, doneProc, clientData, ctrlData);
  67.     reconstructionControlPtr->stripeID = startStripe;
  68.     reconstructionControlPtr->numStripe = numStripe;
  69.     printf("RAID:MSG:Initiating reconstruction %d %d.\n",startStripe,numStripe);
  70.     InitiateStripeHardInit(reconstructionControlPtr);
  71. }
  72.  
  73.  
  74. /*
  75.  *----------------------------------------------------------------------
  76.  *
  77.  * hardInitDoneProc --
  78.  *
  79.  *    Callback procedure for Raid_InitiateHardInit.
  80.  *
  81.  * Results:
  82.  *    None.
  83.  *
  84.  * Side effects:
  85.  *    None.
  86.  *
  87.  *----------------------------------------------------------------------
  88.  */
  89. static void
  90. hardInitDoneProc(reconstructionControlPtr)
  91.     RaidReconstructionControl    *reconstructionControlPtr;
  92. {
  93.     reconstructionControlPtr->doneProc(reconstructionControlPtr->clientData,
  94.         reconstructionControlPtr->status);
  95.     Raid_FreeReconstructionControl(reconstructionControlPtr);
  96. }
  97.  
  98.  
  99. /*
  100.  *----------------------------------------------------------------------
  101.  *
  102.  * Raid_InitiateHardInitFailure --
  103.  *
  104.  *    Causes the initialization of the current stripe to fail.
  105.  *
  106.  * Results:
  107.  *    None.
  108.  *
  109.  * Side effects:
  110.  *    Prints an error message.
  111.  *
  112.  *----------------------------------------------------------------------
  113.  */
  114.  
  115. static void
  116. Raid_InitiateHardInitFailure(reconstructionControlPtr)
  117.     RaidReconstructionControl    *reconstructionControlPtr;
  118. {
  119.     hardInitWriteDoneProc(reconstructionControlPtr, 1);
  120. }
  121.  
  122.  
  123. /*
  124.  *----------------------------------------------------------------------
  125.  *
  126.  * InitiateStripeHardInit --
  127.  *
  128.  *    Reconstructs the parity on a single stripe.
  129.  *
  130.  * Results:
  131.  *    None.
  132.  *
  133.  * Side effects:
  134.  *    Locks stripe.
  135.  *    Parity is updated.
  136.  *
  137.  *----------------------------------------------------------------------
  138.  */
  139.  
  140. static void
  141. InitiateStripeHardInit(reconstructionControlPtr)
  142.     RaidReconstructionControl    *reconstructionControlPtr;
  143. {
  144.     Raid           *raidPtr       = reconstructionControlPtr->raidPtr;
  145.  
  146.  
  147.     int                   ctrlData      = reconstructionControlPtr->ctrlData;
  148.     RaidRequestControl *reqControlPtr = reconstructionControlPtr->reqControlPtr;
  149.     char           *readBuf       = reconstructionControlPtr->readBuf;
  150.  
  151.     int                stripeID      = reconstructionControlPtr->stripeID;
  152.     int                numStripe     = reconstructionControlPtr->numStripe;
  153.     unsigned            firstSector;
  154.     unsigned            nthSector;
  155.  
  156.     firstSector = StripeIDToSector(raidPtr, stripeID);
  157.     nthSector   = NthSectorOfStripe(raidPtr, firstSector);
  158.     if (stripeID >= raidPtr->numStripe || stripeID < 0 || numStripe == 0) {
  159.     hardInitDoneProc(reconstructionControlPtr);
  160.     return;
  161.     }
  162.     Raid_XLockStripe(raidPtr, stripeID);
  163.     reqControlPtr->numReq = reqControlPtr->numFailed = 0;
  164.     AddRaidDataRequests(reqControlPtr, raidPtr, FS_READ,
  165.         firstSector, nthSector, readBuf, ctrlData);
  166.     if (reqControlPtr->numFailed == 0) {
  167.     Raid_InitiateIORequests(reqControlPtr,
  168.         hardInitReadDoneProc,
  169.         (ClientData) reconstructionControlPtr);
  170.     } else {
  171.     Raid_InitiateHardInitFailure(reconstructionControlPtr);
  172.     }
  173. }
  174.  
  175.  
  176. /*
  177.  *----------------------------------------------------------------------
  178.  *
  179.  * hardInitReadDoneProc --
  180.  *
  181.  *    Callback procedure for InitiateStripeHardInit.
  182.  *    Called after the data on a stripe is read.
  183.  *    Calculates the parity and then writes it.
  184.  *
  185.  * Results:
  186.  *    None.
  187.  *
  188.  * Side effects:
  189.  *    Parity write.
  190.  *
  191.  *----------------------------------------------------------------------
  192.  */
  193.  
  194. static void
  195. hardInitReadDoneProc(reconstructionControlPtr, numFailed)
  196.     RaidReconstructionControl    *reconstructionControlPtr;
  197.     int                  numFailed;
  198. {
  199.     Raid           *raidPtr       = reconstructionControlPtr->raidPtr;
  200.     char           *parityBuf     = reconstructionControlPtr->parityBuf;
  201.     int                   ctrlData      = reconstructionControlPtr->ctrlData;
  202.     RaidRequestControl *reqControlPtr = reconstructionControlPtr->reqControlPtr;
  203.     int                stripeID      = reconstructionControlPtr->stripeID;
  204.  
  205.     if (numFailed > 0) {
  206.     Raid_InitiateHardInitFailure(reconstructionControlPtr);
  207.     } else {
  208. #ifndef NODATA
  209.     bzero(parityBuf, raidPtr->bytesPerStripeUnit);
  210. #endif
  211.     XorRaidRequests(reqControlPtr, raidPtr, parityBuf);
  212.     AddRaidParityRequest(reqControlPtr, raidPtr, FS_WRITE,
  213.         (unsigned) StripeIDToSector(raidPtr, stripeID),
  214.         parityBuf, ctrlData);
  215.     Raid_InitiateIORequests(reqControlPtr,
  216.         hardInitWriteDoneProc,
  217.         (ClientData) reconstructionControlPtr);
  218.     }
  219. }
  220.  
  221.  
  222. /*
  223.  *----------------------------------------------------------------------
  224.  *
  225.  * hardInitWriteDoneProc --
  226.  *
  227.  *    Callback procedure for hardInitReadDoneProc.
  228.  *
  229.  * Results:
  230.  *    None.
  231.  *
  232.  * Side effects:
  233.  *    Unlocks stripe and initiates reconstruction for the next stripe.
  234.  *
  235.  *----------------------------------------------------------------------
  236.  */
  237. #ifdef TESTING
  238. #define NUM_REPORT_STRIPE 1
  239. #else
  240. #define NUM_REPORT_STRIPE 100
  241. #endif
  242.  
  243. static void
  244. hardInitWriteDoneProc(reconstructionControlPtr, numFailed)
  245.     RaidReconstructionControl    *reconstructionControlPtr;
  246.     int                 numFailed;
  247. {
  248.     Raid    *raidPtr = reconstructionControlPtr->raidPtr;
  249.     int        stripeID = reconstructionControlPtr->stripeID;
  250.  
  251.     if (numFailed > 0) {
  252.         Raid_ReportHardInitFailure(stripeID);
  253.     reconstructionControlPtr->status = FAILURE;
  254.     }
  255.     if (stripeID % NUM_REPORT_STRIPE == 0) {
  256.     printf("RAID:MSG:%d", stripeID);
  257.     }
  258.     Raid_XUnlockStripe(raidPtr, stripeID);
  259.     reconstructionControlPtr->stripeID++;
  260.     reconstructionControlPtr->numStripe--;
  261.     InitiateStripeHardInit(reconstructionControlPtr);
  262. }
  263.